﻿using System;
using Mbs.ComponentModel.Container.Metadata;

namespace Mbs.ComponentModel.Container.Listner
{
    [Serializable]
    public class LifecycleAdapterListner:KernelListnerAdapter
    {
        private LifecycleListnerManager Manager = new LifecycleListnerManager();
        public LifecycleAdapterListner() : base(LifestyleStage.Created | LifestyleStage.Destroyed) { }

        public override void OnCreated(IComponentInfo info, object instance)
        {
            if (instance != null)
                Manager.Foreach(lisnter => lisnter.OnCreated(instance));
        }

        public override void OnDestroyed(IComponentInfo info, object instance)
        {
            if (instance != null)
                Manager.Foreach(listner => listner.OnDestroyed(instance));
        }
        
    }
}
